<?php
namespace Modules\Shop\Http\Controllers;

use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use Modules\Shop\Entities\Friend;
use Modules\Shop\Http\Requests\FriendRequest;
class FriendController extends Controller
{
    //显示列表
    public function index()
    {
        $data = Friend::paginate(10);
        return view('shop::friend.index', compact('data'));
    }

    //创建视图
    public function create(Friend $friend)
    {
        return view('shop::friend.create',compact('friend'));
    }

    //保存数据
    public function store(FriendRequest $request,Friend $friend)
    {
        $friend->fill($request->all());
        $friend->save();

        return redirect('/shop/friend')->with('success', '保存成功');
    }

    //显示记录
    public function show(Friend $field)
    {
        return view('shop::friend.show', compact('field'));
    }

    //编辑视图
    public function edit(Friend $friend)
    {
        return view('shop::friend.edit', compact('friend'));
    }

    //更新数据
    public function update(FriendRequest $request, Friend $friend)
    {
        $friend->update($request->all());
        return redirect('/shop/friend')->with('success','更新成功');
    }

    //删除模型
    public function destroy(Friend $friend)
    {
        $friend->delete();
        return redirect('shop/friend')->with('success','删除成功');
    }
}
